package com.fuqi.android.zhongcai.business.shuig.view.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.fuqi.android.zhongcai.business.shuig.OrderDict;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderListResult;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGActivity;
import com.fuqi.android.zhongcai.business.shuig.view.widget.ChouchaView;
import com.fuqi.android.zhongcai.utils.ActivityUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Bruce on 2016/10/25.
 */
public class DaiChouChaAdapter extends BaseAdapter {
    private Context context;
    private List<OrderListResult> liststr = new ArrayList<OrderListResult>();

    public DaiChouChaAdapter(Context context, List<OrderListResult> datas) {
        this.context = context;
        this.liststr = datas;
    }

    public void setDate(List<OrderListResult> datas){
        liststr = datas;
        notifyDataSetChanged();
    }
    public List<OrderListResult> getDate(){
        return liststr ;
    }

    public int getCount() {
        return liststr == null ? 0 : liststr.size();
    }

    public OrderListResult getItem(int position) {
        return liststr.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = new ChouchaView(context);
        }
        final OrderListResult data = getItem(position);

        ChouchaView countryView = (ChouchaView) convertView;
        if("0".equals(data.getIS_SELECT())){//1选择过，0未选择
            countryView.setCheck(true);
            countryView.mLyt.setClickable(false);
        }else{
            countryView.setCheck(false);
            countryView.mLyt.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle bundle = new Bundle();
                    bundle.putString("order_id",data.getOrderId());
                    bundle.putString("order_type",data.getOrderType());
                    ActivityUtils.startActivity(context,ShuiGActivity.class,bundle);
                }
            });
        }

        countryView.setAddress(data.getAddArea());
        countryView.setOrigin(data.getContactName());
        countryView.setStatus(OrderDict.getNameByStatus(data.getOrderStatus()));

        return convertView;
    }


}
